Ext.define('Jee.view.EditView',{
    extend: 'Ext.window.Window',
    alias : ['editView'],
    grid:null,
  initComponent : function(){
	   this.buttons = [
            {
                text: 'Save',
                action: 'save',
                scope: this,
                handler: this.saveOrUpdate
            },
            {
                text: 'Cancel',
                scope: this,
                handler: this.close
            }
        ];
    	this.callParent();
  },
  
  buildModelData:function(values){
	 return Jee.Util.formObjToModel(values);
  },
  saveOrUpdateCallback:function(jeeRequest,result){
	  var me = this;
	  me.close();
	  var data = jeeRequest.data;
	  if(data.id && data.id !=''){
		   //刷新
		   me.grid.refresh();
	  }else{
		  me.grid.searchHandler();
	  }
  },
  saveOrUpdate:function(){
	  var me = this;
	  var form   = me.down('form');
	  if (form.getForm().isValid()) {
		  var values = form.getValues();
	      var data = this.buildModelData(values);
	      var jeeRequest = {};
	      jeeRequest.data = data;
	      if(data.id && data.id !=''){
	    	   jeeRequest.serviceId = me.grid.serviceClassCode+'_04';
	      }else{
	    	  jeeRequest.serviceId = me.grid.serviceClassCode+'_03';
	      }
	      Jee.Ajax.request(jeeRequest,{successCallback:function(result){
	    	    me.saveOrUpdateCallback(jeeRequest,result);
	    	  }
	      }); 
	  }
  }
});